package com.study.www.demofilter.config;

import com.study.www.demo.Application;
import lombok.extern.slf4j.Slf4j;
import org.joda.time.DateTime;
import org.springframework.core.annotation.Order;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @author : Administrator.zhuyanpeng
 * @date : 2019/11/15 - 16:44
 */
@Slf4j
@Order(1)
@WebFilter(filterName = "1DemoFilter",urlPatterns = {"/demo/*"},
        asyncSupported = true,
        dispatcherTypes = {DispatcherType.REQUEST,DispatcherType.ASYNC})
public class DemoFilter implements Filter {

    public DemoFilter() {
        log.warn("DemoFilter 的 constructor ;启动时间=>"+new DateTime().toString(Application.DATEFORMAT));
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.warn("DemoFilter 的 init ;启动时间=>"+new DateTime().toString(Application.DATEFORMAT));
    }

    @Override
    public void destroy() {
        log.warn("DemoFilter 的 destroy ;启动时间=>"+new DateTime().toString(Application.DATEFORMAT));
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.warn("DemoFilter 的 doFilter;进入=>"+new DateTime().toString(Application.DATEFORMAT));
        filterChain.doFilter(servletRequest, servletResponse);
        log.warn("DemoFilter 的 doFilter;完毕=>"+new DateTime().toString(Application.DATEFORMAT));
    }
}
